<?php
namespace app\mingteng\controller;
use think\Db;

class Index extends Base {
    public function index(){
        //用户信息
        $admin_info = getAdminInfo(session('admin_id'));
        $this->assign('admin_info',$admin_info);
        //左边栏目
        $this->assign('menu_list', getMenuArr());
        return $this->fetch();
    }
    //欢迎页面
    public function welcome(){
        $this->assign('sys_info',$this->get_sys_info());
        return $this->fetch();
    }
    //基础信息
    private function get_sys_info(){
        $sys_info['os']             = PHP_OS;
        $sys_info['zlib']           = function_exists('gzclose') ? 'YES' : 'NO';//zlib
        $sys_info['safe_mode']      = (boolean) ini_get('safe_mode') ? 'YES' : 'NO';//safe_mode = Off
        $sys_info['timezone']       = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
        $sys_info['curl']			= function_exists('curl_init') ? 'YES' : 'NO';
        $sys_info['web_server']     = $_SERVER['SERVER_SOFTWARE'];
        $sys_info['phpv']           = phpversion();
        $sys_info['ip'] 			= GetHostByName($_SERVER['SERVER_NAME']);
        $sys_info['fileupload']     = @ini_get('file_uploads') ? ini_get('upload_max_filesize') :'unknown';
        $sys_info['max_ex_time'] 	= @ini_get("max_execution_time").'s'; //脚本最大执行时间
        $sys_info['set_time_limit'] = function_exists("set_time_limit") ? true : false;
        $sys_info['domain'] 		= $_SERVER['HTTP_HOST'];
        $sys_info['memory_limit']   = ini_get('memory_limit');
        $mysqlinfo = Db::query("SELECT VERSION() as version");
        $sys_info['mysql_version']  = $mysqlinfo[0]['version'];
        if(function_exists("gd_info")){
            $gd = gd_info();
            $sys_info['gdinfo'] 	= $gd['GD Version'];
        }else {
            $sys_info['gdinfo'] 	= "未知";
        }
        return $sys_info;
    }

    /**
     * ajax 修改指定表数据字段  一般修改状态 比如 是否推荐 是否开启 等 图标切换的
     * table,id_name,id_value,field,value
     */
    public function changeTableVal(){
        $table = I('table'); // 表名
        $id_name = I('id_name'); // 表主键id名
        $id_value = I('id_value'); // 表主键id值
        $field  = I('field'); // 修改哪个字段
        $value  = I('value'); // 修改字段值
        M($table)->where($id_name,$id_value)->save(array($field=>$value)); // 根据条件保存修改的数据
    }


    /*
     * 修改订单价格
     * */
    public function changeOrderPrice(){
        $order_id = I('order_id'); // 表名
        $id_name = I('id_name'); // 表主键id名
        $id_value = I('id_value'); // 表主键id值
        $field  = I('field'); // 修改哪个字段
        $value  = I('value'); // 修改字段值
        
		M('order_goods')->where($id_name,$id_value)->save(array($field=>$value)); // 根据条件保存修改的数据
		
		$goods = M('order_goods')->where('order_id='.$order_id)->select();
        $total = 0;
        foreach ($goods as $k=>$v){
            $total += $goods[$k]['goods_num'] * $goods[$k]['goods_price'];
        }
		M('order')->where('order_id='.$order_id)->save(['goods_price' => $total]);
		
		$goods_name = M('order_goods')->where($id_name,$id_value)->getField('goods_name');
		$map['order_id'] = $order_id;
		$map['action_user'] = session('admin_id'); //操作员
		$map['action_note'] = '修改订单'.$goods_name.'商品单价';
		$map['log_time'] = time();
		M('order_action')->insert($map);	
    }
	

	
}
